using System.Collections.Generic;
using UnityEngine;

namespace JufTools
{
    public class StateMachine : MonoBehaviour
    {
        protected IState currentState;
        protected Dictionary<System.Type, IState> stateTable;
        protected void SwitchOn(IState startState)
        {
            currentState = startState;
            currentState.Enter();
        }
        protected void SwitchOn(System.Type startState)
        {
            currentState = stateTable[startState];
            currentState.Enter();
        }
        public void SwitchState(IState nextState)
        {
            currentState.Exit();
            currentState = nextState;
            currentState.Enter();
        }
        public void SwitchState(System.Type nextState)
        {
            currentState.Exit();
            currentState = stateTable[nextState];
            currentState.Enter();
        }
        protected virtual void Update()
        {
            currentState.LogicalUpdate();
        }
        protected virtual void FixedUpdate()
        {
            currentState.PhysicalUpdate();
        }
    }
}

